export function calculatePosition(component) {
	let top = parseInt(component.style.top);
	let left = parseInt(component.style.left);
	let width = parseInt(component.style.width);
	let height = parseInt(component.style.height);
	let right = left + width;
	let bottom = top + height;
	return { top, left, right, bottom }
}

export function calculateStyle(componentList) {
	let lefts = [];
	let rights = [];
	let tops = [];
	let bottoms = [];
	componentList.forEach(item => {
		lefts.push(item.position.left);
		rights.push(item.position.right);
		tops.push(item.position.top);
		bottoms.push(item.position.bottom);
	});
	let left = Math.min(...lefts);
	let top = Math.min(...tops);
	let right = Math.max(...rights);
	let bottom = Math.max(...bottoms);
	let width = right - left;
	let height = bottom - top;
	return { left, top, width, height }
}

// 组合时重置内部组件的位置
export function resetComponentStyle(componentList, left, top) {
	componentList.forEach(item => {
		item.position.left = item.position.left - left;
		item.position.top = item.position.top - top
		item.style.left = item.position.left + 'px';
		item.style.top = item.position.top + 'px'
	})
}

// 拆分时恢复内部组件的位置
export function recoverComponentStyle(componentList, left, top) {
	componentList.forEach(item => {
		item.style.left = (item.position.left + left) + 'px';
		item.style.top = (item.position.top + top) + 'px'
	})
}